class_name CombatComponent
extends BaseComponent

## 战斗组件

#region 属性
## 生命值缓存
var health_cache:float
#endregion
#region 字段
var hit_box:HitBox:
	get:
		return %HitBox
var hurt_box:HurtBox:
	get:
		return %HurtBox
#endregion
#region 信号
#endregion

#region 基类方法
func init_component(args:Dictionary = {}):
	super(args)
	health_cache = 0
	hit_box.init()
#endregion
#region 公共方法
## 获得HitBox
func get_hit_box() -> HitBox:
	return hit_box
## 获得HurtBox
func get_hurt_box() -> HurtBox:
	return hurt_box
func hurt(message:HurtMessage):
	##TODO 先暂时不考虑防御等抵抗计算
	health_cache -= message.value
	var value = int(health_cache)
	health_cache -= value
	entity.entity_data.set_cost("Health",value)
	message.value = value
	if message.callback and message.callback.is_valid():
		message.callback.call(message)
	## 飘字
	var slot_component:SlotComponent = entity.get_component(SlotComponent)
	var head:Marker2D = slot_component.get_slot_manager().get_slot_by_type(GameEnum.SlotType.Head)
	GameManager.popup_tip(str(abs(message.value)),head.get_canvas_transform() * head.global_position,Constant.DAMAGE_NORMAL_COLOR)
	# 记录StateManager需要的参数
	var state_component:StateComponent = entity.get_component(StateComponent)
	if state_component:
		var state_chart:StateChart = state_component.get_state_chart_manager().chart
		if state_chart:
			var property_name = "Hurt"
			state_chart.set_expression_property(property_name,Engine.get_process_frames())
func recover(message:HurtMessage):
	# TODO 先暂时不考虑恢复加成等计算
	health_cache += message.value
	var value = int(health_cache)
	health_cache -= value
	entity.entity_data.set_cost("Health",value)
	message.value = value
	if message.callback and message.callback.is_valid():
		message.callback.call(message)
	var slot_component:SlotComponent = entity.get_component(SlotComponent)
	var head:Marker2D = slot_component.get_slot_manager().get_slot_by_type(GameEnum.SlotType.Head)
	GameManager.popup_tip(str(abs(message.value)),head.get_canvas_transform() * head.global_position,Constant.RECOVER_NORMAL_COLOR)
	# 记录StateManager需要的参数
	var state_component:StateComponent = entity.get_component(StateComponent)
	if state_component:
		var state_chart:StateChart = state_component.get_state_chart_manager().chart
		if state_chart:
			var property_name = "Recover"
			state_chart.set_expression_property(property_name,Engine.get_process_frames())
#endregion
#region 私有方法
#endregion
#region 生命周期函数
#endregion
